using System.Configuration;
using System.Data.SqlClient;
using NHibernate;
using SinBiota.Model.Persistence.ComplexQueries.Implementation;
using SinBiota.Model.Persistence.ComplexQueries.Interfaces;
using SinBiota.Model.Persistence.Repositories.Implementation;
using SinBiota.Model.Persistence.Repositories.Interfaces;
using SinBiota.Model.Persistence.SessionManager;
using StructureMap.Configuration.DSL;

namespace Sinbiota.Web.Initialization.StructureMap
{
    public class PersistenceRegistry : Registry
    {
        public PersistenceRegistry()
        {
            // Repositories
            For<IConservationUnitRepository>().Use<ConservationUnitRepository>();
            For<IDrainageBasinRepository>().Use<DrainageBasinRepository>();
            For<IEcosystemRepository>().Use<EcosystemRepository>();
            For<IHabitatRepository>().Use<HabitatRepository>();
            For<IInstitutionRepository>().Use<InstitutionRepository>();
            For<IKeywordRepository>().Use<KeywordRepository>();
            For<IMethodRepository>().Use<MethodRepository>();
            For<IMicroHabitatRepository>().Use<MicroHabitatRepository>();
            For<IMunicipalityRepository>().Use<MunicipalityRepository>();
            For<IProjectRepository>().Use<ProjectRepository>();
            For<IUserRepository>().Use<UserRepository>();
            For<ILogRepository>().Use<LogRepository>();
            For<IDepositaryUnitRepository>().Use<DepositaryUnitRepository>();
            For<IPublicationRepository>().Use<PublicationRepository>();
            For<IOccurrenceRepository>().Use<OccurrenceRepository>();
            For<ITaxonRepository>().Use<TaxonRepository>();
            For<IOccurrenceAuthorRepository>().Use<OccurrenceAuthorRepository>();
            For<ILocationRepository>().Use<LocationRepository>();
            For<ISpecimenRepository>().Use<SpecimenRepository>();
            For<IDepositaryUnitRecordRepository>().Use<DepositaryUnitRecordRepository>();
            For<ITaxonReferenceRepository>().Use<TaxonReferenceRepository>();
            For<IPasswordResetRequestRepository>().Use<PasswordResetRequestRepository>();
            //Complex Queries:
            For<IRepositoryStatistics>().Use<RepositoryStatistics>();
            For<IAquaticDataRepository>().Use<AquaticDataRepository>();

            // Session Management:
            For<ISessionFactory>().Singleton().Use(NHibernateSessionFactory.CreateSessionFactory(ConfigurationManager.ConnectionStrings["domainDB"].ConnectionString));
            //For<ISession>().HttpContextScoped().Use(context => context.GetInstance<ISessionFactory>().OpenSession());
            For<ISession>().Use(context => context.GetInstance<ISessionFactory>().OpenSession());
            For<IConnectionFactory>().Use<ConnectionFactory>();
        }
    }
}